{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d7c195e",
   "metadata": {},
   "outputs": [],
   "source": [
    "#1.需要导入需要的requests模块 \n",
    "import requests "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8de4794b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#2.输入我们需要的API网站注册的API_Key\\API_Secret\n",
    "API_Key =\"你的face++ APIkey\" \n",
    "API_Secret =\"你的face++ API_secret\" \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0289b7ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "API_Key = \"56FsUuf66IWUePETheadbwnh2kBPESsS\"\n",
    "API_Secret = \"MXBkklqD-C81dr64EgslFsGq5Car7pX7\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aaf54fcf",
   "metadata": {},
   "source": [
    "* 1.整理："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "752e6bd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.导入需要的requests模块\n",
    "import requests\n",
    "\n",
    "# 2.输入我们需要API（face++）网站注册的API_Key\\Secret\n",
    "API_Key = \"56FsUuf66IWUePETheadbwnh2kBPESsS\"\n",
    "API_Secret = \"MXBkklqD-C81dr64EgslFsGq5Car7pX7\"\n",
    "\n",
    "# 3.准备base URL(face detect) API测试接口的url\n",
    "base_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "\n",
    "# 4.请求方法：POST\n",
    "\n",
    "# 5.准备请求参数：payload\n",
    "payload = {\n",
    "    \"api_key\":API_Key,\n",
    "    \"api_secret\":API_Secret,\n",
    "    \"image_url\":\"http://thumb10.jfcdns.com/thumb/up/2017-8/201782115518958221215010_600_0.jpg\",\n",
    "    \"return_landmark\":1,\n",
    "    \"return_attributes\":\"gender,age,smiling\"\n",
    "\n",
    "}\n",
    "# 6.请求数据\n",
    "\n",
    "r = requests.post(base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "be86df2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [403]>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0730cf0f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648279619,81e6db45-c17d-458a-a078-29092689028e',\n",
       " 'time_used': 72,\n",
       " 'error_message': 'AUTHORIZATION_ERROR: Insufficient Account Balance'}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d3d1bf5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "face_detect = r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d8ab8f66",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648279619,81e6db45-c17d-458a-a078-29092689028e',\n",
       " 'time_used': 72,\n",
       " 'error_message': 'AUTHORIZATION_ERROR: Insufficient Account Balance'}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41f1369c",
   "metadata": {},
   "source": [
    "## 2. 人脸分析API"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "f7e39022",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\npayload = {\\n    'api_key':API_key,\\n    'api_secret':API_sercret,\\n    'face_tokens':face_tokens,\\n    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus',\\n    'beauty_score_min':0,\\n    'beauty_score_max':100\\n    \\n}\\n\""
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. url \n",
    "# Analyze_base_url = \"https://api-cn.faceplusplus.com/facepp/v3/face/analyze\"\n",
    "\n",
    "# 2. api账户/通行证\n",
    "# API_key = '你的KEY'\n",
    "# API_sercret = '你的SERCRET'\n",
    "\n",
    "# 3 POST\n",
    "\n",
    "# 4. 权限：所有 API Key 都可以调用本 API\n",
    "\n",
    "# 5. payload： 酬载, 必要阅读api文档中的 *必选项* 和 *可选性*，及 *参数说明*\n",
    "\"\"\"\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_sercret,\n",
    "    'face_tokens':face_tokens,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus',\n",
    "    'beauty_score_min':0,\n",
    "    'beauty_score_max':100\n",
    "    \n",
    "}\n",
    "\"\"\"\n",
    "\n",
    "# 6. requests\n",
    "\n",
    "# r_analyze = requests.post(url = Analyze_base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "cc68d2d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. url \n",
    "Analyze_base_url = \"https://api-cn.faceplusplus.com/facepp/v3/face/analyze\"\n",
    "\n",
    "# 2. api账户/通行证\n",
    "API_key = '56FsUuf66IWUePETheadbwnh2kBPESsS'\n",
    "API_sercret = 'MXBkklqD-C81dr64EgslFsGq5Car7pX7'\n",
    "\n",
    "# 3 POST\n",
    "\n",
    "# 4. 权限：所有 API Key 都可以调用本 API\n",
    "\n",
    "# 5. payload： 酬载, 必要阅读api文档中的 *必选项* 和 *可选性*，及 *参数说明*\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_sercret,\n",
    "   \n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,beauty,mouthstatus,eyegaze,skinstatus',\n",
    "    'beauty_score_min':0,\n",
    "    'beauty_score_max':100\n",
    "    \n",
    "}\n",
    "\n",
    "# 6. requests\n",
    "\n",
    "r_analyze = requests.post(url = Analyze_base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "92a674cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [403]>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_analyze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "7b40e940",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 78,\n",
       " 'error_message': 'AUTHORIZATION_ERROR: Insufficient Account Balance',\n",
       " 'request_id': '1648279988,b351fbcf-7927-4faa-a4cf-c59fe6814ae9'}"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_analyze.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "7d887938",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54ecd7a1",
   "metadata": {},
   "source": [
    "### 3. 人脸对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ed7e526d",
   "metadata": {},
   "outputs": [],
   "source": [
    "base_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect'\n",
    "\n",
    "API_key = \"56FsUuf66IWUePETheadbwnh2kBPESsS\"\n",
    "API_secret = \"MXBkklqD-C81dr64EgslFsGq5Car7pX7\"\n",
    "\n",
    "\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret,\n",
    "    'image_url':'https://img2.baidu.com/it/u=2297031746,3126288543&fm=253&fmt=auto&app=138&f=JPEG?w=362&h=500'    \n",
    "}\n",
    "\n",
    "r_1 = requests.post(base_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "06870180",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [403]>"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "097a3460",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648279619,81e6db45-c17d-458a-a078-29092689028e',\n",
       " 'time_used': 72,\n",
       " 'error_message': 'AUTHORIZATION_ERROR: Insufficient Account Balance'}"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a66540bc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
